package cn.kone.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.kone.mapper.CustomerCarMapper;
import cn.kone.pojo.domain.CustomerCar;
import cn.kone.service.ICustomerCarService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 客户车辆 服务实现类
 * </p>
 *
 * @author yuyu
 * @since 2024-03-24
 */
@Service
public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, CustomerCar> implements ICustomerCarService {

    //查询车辆列表
    @Override
    public Object carlist() {
        return list(new LambdaQueryWrapper<CustomerCar>().eq(CustomerCar::getCustomerId, StpUtil.getLoginIdAsLong()));
    }

    //新增车辆
    @Override
    public Object carAdd(CustomerCar customerCar) {
        //根据车牌先查询出是否有相同车牌
        CustomerCar one = getOne(new LambdaQueryWrapper<CustomerCar>().eq(CustomerCar::getCarPlate, customerCar.getCarPlate()));
        customerCar.setCustomerId(StpUtil.getLoginIdAsLong());
        if (one != null) {
            customerCar.setId(one.getId());
        }
        saveOrUpdate(customerCar);
        return null;
    }
}
